###2020.12.29
setwd("E:/5hmc_file/2_5hmc_yjp_bam/ASM/")
file=read.csv("20201120/at.least.one.AShM.in.DC.add.BF.beta0.add.CCHC.csv",head=T)
filea=read.csv("20201112做汇总表/all.FDR.sig.at.least.one.add.direction.same.diff.csv",head=T)
filea$id=paste(filea$Chr,filea$Start,sep = ":")
filea1=filea[filea$FDR.sig>1,]

file$id=paste(file$Chr,file$Start,sep=":")
file1=file[file$pattern.not.rm.dupl.num.DC>1,]
file2=file1[file1$BF_in_DC>1,]
file3=file1[file1$BF_in_DC>10,]

result=as.data.frame(table(file2$Func.refGene))
result$ratio=round(result$Freq/sum(result$Freq),4)
result=result[order(result$Freq),]
result$lognum=log(result$ratio*1000)

library(ggplot2)
library(RColorBrewer)
library(ggsci)
p2=ggplot(result,aes(x=reorder(Var1,Freq), y=lognum, fill=Var1))+ geom_bar(stat="identity", color="black")+coord_polar()+theme_bw()+
  ylim(-5,12)+theme(
    panel.grid = element_blank(),
    panel.border= element_blank(),
    axis.text.y = element_blank(),
    axis.text.x = element_blank(),
    axis.ticks = element_blank(),
    axis.title = element_blank()
  )+geom_text(aes(label = paste(Var1,paste0(round(ratio,4)*100,"%"))),data = subset(result,Freq<20),vjust = "left", hjust = "outward", color = "dark blue", fontface="bold")+
  geom_text(aes(label = paste0(Var1,"\n",paste0(round(ratio,4)*100,"%"))),data = subset(result,Freq>=20),vjust = "left", hjust = "outward", color = "dark blue", fontface="bold")
p2+scale_fill_npg()+guides(fill=F) 


###						下面是以前的代码
#########################con.file
file2=read.table("E:/5hmc_file/组织特异性表达/nobias_AShM.hg19_multianno.csv",head=T,sep=",")
result2=data.frame(matrix(NA,1,ncol=3))
names(result2)=col_names
result2=result2[-1,]
group2=unique(file2$Func.refGene)
for(i in group2){
  result_tmp=data.frame(matrix(NA,1,ncol=3))
  names(result_tmp)=col_names
  file1=file2[file2$Func.refGene==i,]
  result_tmp[,1]=i
  result_tmp[,2]=dim(file1)[1]
  result_tmp[,3]=dim(file1)[1]/dim(file2)[1]
  result2=rbind(result2,result_tmp)
}
result2=result2[-c(11:12),]
result2$lognum=log(round(result2$group_ratio,4)*10000)
p3=ggplot(result2,aes(x=reorder(group,num), y=lognum, fill=group))+ geom_bar(stat="identity", color="black")+coord_polar()+theme_bw()+
  ylim(-5,12)+theme(
    panel.grid = element_blank(),
    panel.border= element_blank(),
    axis.text.y = element_blank(),
    axis.text.x = element_blank(),
    axis.ticks = element_blank(),
    axis.title = element_blank()
  )+geom_text(aes(label = paste0(group,"\n",paste0(round(group_ratio,4)*100,"%"))),data = result2,vjust = "left", hjust = "outward", color = "dark blue", fontface="bold")


p3+scale_fill_npg()+guides(fill=F) 
